<template>
	<view>
		<view class="ipt-wrap">
			<view class="item-wrap">
				<view class="left">
					旧密码
				</view>
				<view class="right">
					<input class="uni-input" password v-model="oldPassword"  placeholder="请输入旧密码" />
				</view>
			</view>
			
			<view class="item-wrap">
				<view class="left">
					新密码
				</view>
				<view class="right">
					<input class="uni-input" password v-model="newPassword"  placeholder="请输入新的密码" />
				</view>
			</view>
			
			<view class="item-wrap">
				<view class="left">
					确认密码
				</view>
				<view class="right">
					<input class="uni-input" password v-model="newPassword2"  placeholder="请再次输入新的密码" />
				</view>
			</view>
			
		</view>
		<view class="tip-wrap">
			密码必须是8-16位英文字母、数字、字符组合
			<view>
				（不能是纯数字）
			</view>
		</view>
	</view>
</template>


<script>
	///soil/water/sys/user/edit/modifyPassword
	import md5 from '../login/md5.js'
	export default{
		data(){
			return {
				user:{},
				newPassword2:'',
				newPassword:'',
				oldPassword:'',
				
			}
		},
		onLoad(){
			this.user=JSON.parse(uni.getStorageSync("userinfo"))
		},
		onNavigationBarButtonTap(e) {
			this.changepwd()
		},
		methods: {
			changepwd(){
				let that=this
				if(this.newPassword==''){
					uni.showToast({
					    title: '请输入新的密码',
					    duration:4000,
						icon:'none'
					});
					return
				}
				if(this.newPassword2==''){
					uni.showToast({
					    title: '请再次输入新的密码',
					    duration:4000,
						icon:'none'
					});
					return
				}
				if(this.oldPassword==''){
					uni.showToast({
					    title: '请输入旧密码',
					    duration:4000,
						icon:'none'
					});
					return
				}
				
				if(this.newPassword!=this.newPassword2){
					uni.showToast({
					    title: '两次输入密码不同',
					    duration:4000,
						icon:'none'
					});
					return
				}
				that.apipost('/soil/water/sys/user/edit/modifyPassword',{
					newPassword:md5.hex_md5(that.newPassword),
					oldPassword:md5.hex_md5(that.oldPassword),
					userNo:that.user.userNo
				},false).then(res => {
					
					
					if(res.code==1){
						uni.showToast({
							icon: 'none',
							duration:4000,
							title: '修改成功'
						});
						setTimeout(function(){
							uni.navigateBack({
								delta:1
							})
						},800)
					}
					
				}).catch(err=>{
					console.log(err)
				});
			},
			loginClick(){
				
				
				let that=this
				if(this.mobile==''||this.pwd==''){
					uni.showToast({
					    title: '账号密码不能为空',
					    duration:4000,
						icon:'none'
					});
					return
				}
				
				that.apiget('/soil/water/sys/login/doLogin',{
					loginName:that.mobile,
					password:md5.hex_md5(that.pwd)
				},false).then(res => {
					console.log(res)
					
					if(res.code==1){
						uni.setStorageSync("auth_token",res.object)
						that.getuserinfo()
						//uni.setStorageSync("mobile",that.mobile)
						// uni.switchTab({
						//     url: '/pages/index/index'
						// });
					}
					
				}).catch(err=>{
					console.log(err)
				});
			},
			
			
		},

	}
</script>
<style>
	.tip-wrap{
		margin-top:30rpx;
		line-height:54rpx;
		padding-left:40rpx;
	}
	page{
		height:100%;
		background:#F5F9FF;
	}
	.ipt-wrap{
		margin-top:80rpx;
		padding-left:40rpx;
		background:#fff;
	}
	.item-wrap{
		border-bottom:1rpx solid rgba(63,140,255,0.2);;
		color:#00041A;
		height:95rpx;
		display:flex;
		align-items: center;
		justify-content: space-between;
	}
</style>